local scene = director:createScene()

function scene:setUp(event)
    dbg.print("sceneGame:setUp")
	
	ads:show(false)
	
	pause = false
	if flag then
		flag = false
		local allScaleX = 320/director.displayWidth
		local allScaleY = 480/director.displayHeight
		
		--------Draw background
		local screenPartSeven = director:createSprite(160/allScaleX, 339/allScaleY, "img/part3.png")
		screenPartSeven.xAnchor=0.5; screenPartSeven.yAnchor=0
		screenPartSeven.zOrder = 0
		screenPartSeven.xScale = 1/allScaleX
		screenPartSeven.yScale = 1/allScaleY
		
		local screenPartSix = director:createSprite(160/allScaleX, 274/allScaleY, "img/part2.png")
		screenPartSix.xAnchor=0.5; screenPartSix.yAnchor=0
		screenPartSix.zOrder = 0
		screenPartSix.xScale = 1/allScaleX
		screenPartSix.yScale = 1/allScaleY
		
		local screenPartFive = director:createSprite(160/allScaleX, 213/allScaleY, "img/part1a.png")
		screenPartFive.xAnchor=0.5; screenPartFive.yAnchor=0
		screenPartFive.zOrder = 2
		screenPartFive.xScale = 1/allScaleX
		screenPartFive.yScale = 1/allScaleY
		
		local screenPartFour = director:createSprite(160/allScaleX, 161/allScaleY, "img/part2.png")
		screenPartFour.xAnchor=0.5; screenPartFour.yAnchor=0
		screenPartFour.zOrder = 0
		screenPartFour.xScale = 1/allScaleX
		screenPartFour.yScale = 1/allScaleY
		
		local screenPartThree = director:createSprite(160/allScaleX, 100/allScaleY, "img/part1a.png")
		screenPartThree.xAnchor=0.5; screenPartThree.yAnchor=0
		screenPartThree.zOrder = 2
		screenPartThree.xScale = 1/allScaleX
		screenPartThree.yScale = 1/allScaleY
		
		local screenPartTwo = director:createSprite(160/allScaleX, 48/allScaleY, "img/part2.png")
		screenPartTwo.xAnchor=0.5; screenPartTwo.yAnchor=0
		screenPartTwo.zOrder = 0
		screenPartTwo.xScale = 1/allScaleX
		screenPartTwo.yScale = 1/allScaleY
		
		local screenPartOne = director:createSprite(160/allScaleX, 0/allScaleY, "img/part1.png")
		screenPartOne.xAnchor=0.5; screenPartOne.yAnchor=0
		screenPartOne.zOrder = 2
		screenPartOne.xScale = 1/allScaleX
		screenPartOne.yScale = 1/allScaleY
		
		local buttonRestart = director:createSprite(160/allScaleX, -100/allScaleY, "img/button.png")
			buttonRestart.xAnchor=0.5; buttonRestart.yAnchor=0.5
			buttonRestart.xScale=.7/allScaleX; buttonRestart.yScale=.5/allScaleY; 
			buttonRestart.zOrder = 3
			buttonRestart.isVisible =false
			
		local buttonQuit = director:createSprite(160/allScaleX, -150/allScaleY, "img/button.png")
			buttonQuit.xAnchor=0.5; buttonRestart.yAnchor=0.5
			buttonQuit.xScale=.7/allScaleX; buttonRestart.yScale=.5/allScaleY; 
			buttonQuit.zOrder = 7
			buttonQuit.isVisible =false
		
		local labelRestart = director:createLabel(160/allScaleX, 50/allScaleY, "Restart")
			labelRestart.xAnchor=0.5;
			labelRestart.zOrder = 3
			labelRestart. hAlignment="center"
			labelRestart.y = buttonRestart.y;
			labelRestart.xScale = 1/allScaleX
			labelRestart.yScale = 1/allScaleY
			labelRestart.isVisible =false
		local scoreRectangle = director:createRectangle( { x=60/allScaleX, y=140/allScaleY, w=200/allScaleX, h=200/allScaleY, color=color.teal, zOrder = 4 } )
			scoreRectangle.strokeColor=color.black
			scoreRectangle.isVisible =false
		local scoreWin = director:createLabel(160/allScaleX, 290/allScaleY, "¡TIME OUT!")
			scoreWin.zOrder = 5
			scoreWin.hAlignment="center"
			scoreWin.xAnchor=0.5;
			scoreWin.color = color.black
			scoreWin.xScale = 1/allScaleX
			scoreWin.yScale = 1/allScaleY
			scoreWin.isVisible =false
		local scoreTitle = director:createLabel(scoreWin.x, scoreWin.y-60/allScaleY, "Your Score is:")
			scoreTitle.zOrder = 5
			scoreTitle.hAlignment="center"
			scoreTitle.xAnchor=0.5;
			scoreTitle.color = color.black
			scoreTitle.xScale = 1/allScaleX
			scoreTitle.yScale = 1/allScaleY
			scoreTitle.isVisible =false
		local scoreText = director:createLabel(scoreWin.x, scoreWin.y-110/allScaleY, "")
			scoreText.text = scoreNumber
			scoreText.zOrder = 5
			scoreText.hAlignment="center"
			scoreText.xAnchor=0.5;
			scoreText.color = color.black
			scoreText.xScale = 1/allScaleX
			scoreText.yScale = 1/allScaleY
			scoreText.isVisible =false
			
		--pause menu
		local labelQuit = director:createLabel(160/allScaleX, 150/allScaleY, "Quit")
			labelQuit.xAnchor=0.5
			labelQuit.zOrder = 10
			labelQuit.hAlignment="center"
			labelQuit.y = buttonQuit.y + 20
			labelQuit.xScale = 1/allScaleX
			labelQuit.yScale = 1/allScaleY
			labelQuit.isVisible = false
				
	-----------Draw moles
		
		local moles = {};
		math.randomseed (os.time ())
		
		for i = 1, 9 do
			if (math.random(1, 2) == 1) then
				moles[i] = director:createSprite(61/allScaleX, -12/allScaleY, "img/mole.png")
			else 
				moles[i] = director:createSprite(61/allScaleX, -12/allScaleY, "img/mole2.png")
			end
			moles[i].xAnchor=0.5; moles[1].yAnchor=0
			moles[i].zOrder = 1
			moles[i].name = ""
			moles[i].xScale = .9/allScaleX
			moles[i].yScale = 1/allScaleY
			moles[i].result = -999;
		end
		
		moles[1].x = 61/allScaleX
		moles[1].y = -12/allScaleY
		
		moles[2].x = 157/allScaleX
		moles[2].y = -12/allScaleY
		
		moles[3].x = 252/allScaleX
		moles[3].y = -12/allScaleY
		
		moles[4].x = 61/allScaleX
		moles[4].y = 101/allScaleY
		
		moles[5].x = 157/allScaleX
		moles[5].y = 101/allScaleY
		
		moles[6].x = 252/allScaleX
		moles[6].y = 101/allScaleY
		
		moles[7].x = 61/allScaleX
		moles[7].y = 214/allScaleY
		
		moles[8].x = 157/allScaleX
		moles[8].y = 214/allScaleY
		
		moles[9].x = 252/allScaleX
		moles[9].y = 214/allScaleY
		
		------Create labels
		local  labels = {}
		
		for i = 1, 9 do
			labels[i] = director:createLabel({x=0/allScaleX, y=23, hAlignment="center", color=color.black })
			moles[i]:addChild(labels[i])
		end
			
		local labelScoreTitle = director:createLabel({x=10/allScaleX, y=440/allScaleY, hAlignment="left", color=color.black, text="Score: ", xScale=1/allScaleX, yScale=1/allScaleY})
		local labelScoreNumber = director:createLabel({x=90/allScaleX, y=440/allScaleY, hAlignment="left", color=color.black, text="", xScale=1/allScaleX, yScale=1/allScaleY})
		local labelTimeTitle = director:createLabel({x=200/allScaleX, y=440/allScaleY, hAlignment="left", color=color.black, text="Time: ", xScale=1/allScaleX, yScale=1/allScaleY})
		local labelTimeNumber = director:createLabel({x=270/allScaleX, y=440/allScaleY, hAlignment="left", color=color.black, text="", xScale=1/allScaleX, yScale=1/allScaleY})

		local labelQuestionOne = director:createLabel({x=10/allScaleX, y=380/allScaleY, color=color.black, text = "Select the operation", hAlignment="left", xScale=1/allScaleX, yScale=1/allScaleY})
		
		local labelQuestion = director:createLabel({x=10/allScaleX, y=350/allScaleY, color=color.black, text = "that gives: ", hAlignment="left", xScale=1/allScaleX, yScale=1/allScaleY})

		local gameTime = 0;
		local startAnimationOne = 0;
		local startAnimationTwo = 0;
		local startAnimationThree = 0;
		local startAnimationFour = 0;
		local startAnimationFive = 0;
		local startAnimationSix = 0;
		local startAnimationSeven = 0;
		local startAnimationEight = 0;
		local startAnimationNine = 0;
		local moleAleatory = 0;
		local timeAnimationOneA = 0;
		local timeAnimationOneB = 0;
		local timeAnimationTwoA = 0;
		local timeAnimationTwoB = 0;
		local timeAnimationThreeA = 0;
		local timeAnimationThreeB = 0;
		local timeAnimationFourA = 0;
		local timeAnimationFourB = 0;
		local timeAnimationFiveA = 0;
		local timeAnimationFiveB = 0;
		local timeAnimationSixA = 0;
		local timeAnimationSixB = 0;
		local timeAnimationSevenA = 0;
		local timeAnimationSevenB = 0;
		local timeAnimationEightA = 0;
		local timeAnimationEightB = 0;
		local timeAnimationNineA = 0;
		local timeAnimationNineB = 0;
		local operatorAleatory = 0;
		local startQuestion = 0;
		local numberOne = 0;
		local numberTwo = 0;
		local numberResult = 0;
		local selectMole = 0;
		local moleTrue = 0;
		local labelOperator = "";
		local moleWin = "";
		local timeLeft = 30;
		local scoreNumber = 0;
		local runGame = "run";
		local finalSeconds = 5;
		local lastTime = 0
		
		system.debugTime = nil
		system.gameTime = 0
		system.timers = {}
		localTime = 0
		
		local move = function()
			if (pause) then
				scoreWin.text = "PAUSED"
				buttonRestart.isVisible = true
				buttonRestart.y = 10/allScaleY
				labelRestart.y = buttonRestart.y
				labelQuestion.isVisible = false
				labelQuestionOne.isVisible = false
				labelRestart.isVisible = true
				scoreRectangle.isVisible = true
				scoreTitle.isVisible = false
				scoreWin.isVisible = true
				scoreText.isVisible = false
				buttonQuit.isVisible = true
				labelQuit.isVisible = true
				buttonQuit.y = 150/allScaleY;
				labelQuit.y = buttonQuit.y+20;
			else
				buttonQuit.y = -150/allScaleY;
				labelQuit.isVisible = false
				if (runGame == "run") then
					buttonQuit.isVisible = false
					buttonRestart.isVisible = false
					buttonRestart.y = -100/allScaleY
					labelRestart.y = buttonRestart.y
					labelQuestion.isVisible = true
					labelQuestionOne.isVisible = true
					labelRestart.isVisible = false
					scoreRectangle.isVisible = false
					scoreTitle.isVisible = false
					scoreWin.isVisible = false
					scoreText.isVisible = false
				
					function system:getTime()
						if self.debugTime then
							return self.debugTime
						else
							return self.gameTime
						end
					end
					
					local startMole = function (number)
						moles[number].a = math.random(1,20)
						if (selectGame == "expert") then
							oper = math.random(1,4)
							else
							oper = math.random(1,2)
						end
							
						if (math.random(1,10) > 5) then
							if (oper == 1) then
								local sumLoop = true
								while (sumLoop) do
									moles[number].b = numberResult - moles[number].a
									if (moles[number].a > numberResult) then
										moles[number].a = math.random(1,20)
										else
										sumLoop = false
									end
								end
								labels[number].text = moles[number].a.. "+" ..moles[number].b
								moles[number].result = moles[number].a + moles[number].b;
							elseif (oper == 2) then
								moles[number].b = numberResult + moles[number].a
								labels[number].text = moles[number].b.. "-" ..moles[number].a
								moles[number].result = moles[number].b - moles[number].a;
							elseif (oper == 3) then
								multiplicationLoop = true
								while (multiplicationLoop) do
									moles[number].b = numberResult / moles[number].a
									if (moles[number].a > numberResult or moles[number].b % 1 ~= 0) then
										moles[number].a = math.random(1,20)
									else
										multiplicationLoop = false
									end
								end
								labels[number].text = moles[number].a .."x".. moles[number].b
								moles[number].result = moles[number].a * moles[number].b;
							else 
								divisionLoop = true
								while (divisionLoop) do
									moles[number].b = moles[number].a * numberResult
									if (moles[number].b > 99 or moles[number].b % 1 ~= 0) then
										moles[number].a = math.random(1,20)
									else
										divisionLoop = false
									end
								end
								labels[number].text = moles[number].b .."/".. moles[number].a
								moles[number].result = moles[number].b / moles[number].a;
							end
						else
							moles[number].b = math.random(1,10)
							if (oper == 1) then
								labels[number].text = moles[number].a .."+".. moles[number].b
								moles[number].result = moles[number].a + moles[number].b
							elseif (oper == 2) then
								labels[number].text = moles[number].a .."-".. moles[number].b
								moles[number].result = moles[number].a - moles[number].b
							elseif (oper == 3) then
								labels[number].text = moles[number].a .."x".. moles[number].b
								moles[number].result = moles[number].a * moles[number].b
							else 
								labels[number].text = moles[number].a .."/".. moles[number].b
								moles[number].result = moles[number].a / moles[number].b
							end
						end
					end
					
					gameTime = math.floor(system:getTime()*100)/100
					if (gameTime % .4 == 0) then
						
						moleAleatory = math.random(1, 9)
						
						if (moleAleatory == 1) then
							if (startAnimationOne == 0) then
								timeAnimationOneA = gameTime
								timeAnimationOneB = gameTime + 2
								startAnimationOne = 1
								startMole(moleAleatory)
							else
								moleAleatory = math.random(1, 9)
							end
						elseif (moleAleatory == 2) then
							if (startAnimationTwo == 0) then
								timeAnimationTwoA = gameTime
								timeAnimationTwoB = gameTime + 2
								startAnimationTwo = 1
								startMole(moleAleatory)
							else
								moleAleatory = math.random(1, 9)
							end
						elseif (moleAleatory == 3) then
							if (startAnimationThree == 0) then
								timeAnimationThreeA = gameTime
								timeAnimationThreeB = gameTime + 2
								startAnimationThree = 1
								startMole(moleAleatory)
							else
								moleAleatory = math.random(1, 9)
							end
						elseif (moleAleatory == 4) then
							if (startAnimationFour == 0) then
								timeAnimationFourA = gameTime
								timeAnimationFourB = gameTime + 2
								startAnimationFour = 1
								startMole(moleAleatory);
							else
								moleAleatory = math.floor (1, 9)
							end
						elseif (moleAleatory == 5) then
							if (startAnimationFive == 0) then
								timeAnimationFiveA = gameTime
								timeAnimationFiveB = gameTime + 2
								startAnimationFive = 1
								startMole(moleAleatory);
							else
								moleAleatory = math.random(1, 9)
							end
						elseif (moleAleatory == 6) then
							if (startAnimationSix == 0) then
								timeAnimationSixA = gameTime
								timeAnimationSixB = gameTime + 2
								startAnimationSix = 1
								startMole(moleAleatory);
							else
								moleAleatory = math.random(1, 9)
							end
						elseif (moleAleatory == 7) then
							if (startAnimationSeven == 0) then
								timeAnimationSevenA = gameTime
								timeAnimationSevenB = gameTime + 2
								startAnimationSeven = 1
								startMole(moleAleatory);
							else
								moleAleatory = math.random(1, 9)
							end
						elseif (moleAleatory == 8) then
							if (startAnimationEight == 0) then
								timeAnimationEightA = gameTime
								timeAnimationEightB = gameTime + 2
								startAnimationEight = 1
								startMole(moleAleatory);
							else
								moleAleatory = math.random(1, 9)
							end
						elseif (moleAleatory == 9) then
							if (startAnimationNine == 0) then
								timeAnimationNineA = gameTime
								timeAnimationNineB = gameTime + 2
								startAnimationNine = 1
								startMole(moleAleatory);
							else
								moleAleatory = math.random(1, 9)
							end
						end
					end
						
					if (timeAnimationOneA < timeAnimationOneB) then
						if (startAnimationOne == 1) then
							moles[1].y = moles[1].y +.25/allScaleY
							timeAnimationOneA = gameTime
						end
						if (startAnimationOne == 2) then
							moles[1].y = moles[1].y -.25/allScaleY
							timeAnimationOneA = gameTime
						end
					end
					if (timeAnimationOneA >= timeAnimationOneB) then
						if (startAnimationOne == 1) then
							timeAnimationOneB = timeAnimationOneB + 2
							startAnimationOne = 2
						end
					end
					if (timeAnimationOneA >= timeAnimationOneB) then	
						if (startAnimationOne == 2) then
							startAnimationOne = 0
							moles[1].y = -12/allScaleY
							moles[1].result = -999
						end
					end
					
					if (timeAnimationTwoA < timeAnimationTwoB) then
						if (startAnimationTwo == 1) then
							moles[2].y = moles[2].y +.25/allScaleY
							timeAnimationTwoA = gameTime
						end
						if (startAnimationTwo == 2) then
							moles[2].y = moles[2].y -.25/allScaleY
							timeAnimationTwoA = gameTime
						end
					end
					if (timeAnimationTwoA >= timeAnimationTwoB) then
						if (startAnimationTwo == 1) then
							timeAnimationTwoB = timeAnimationTwoB + 2
							startAnimationTwo = 2
						end
					end
					if (timeAnimationTwoA >= timeAnimationTwoB) then
						if (startAnimationTwo == 2) then
							startAnimationTwo = 0
							moles[2].y = -12/allScaleY
							moles[2].result = -999
						end
					end
					
					if (timeAnimationThreeA < timeAnimationThreeB) then
						if (startAnimationThree == 1) then
							moles[3].y = moles[3].y +.25/allScaleY
							timeAnimationThreeA = gameTime
						end
						if (startAnimationThree == 2) then
							moles[3].y = moles[3].y -.25/allScaleY
							timeAnimationThreeA = gameTime
						end
					end
					if (timeAnimationThreeA >= timeAnimationThreeB) then
						if (startAnimationThree == 1) then
							timeAnimationThreeB  = timeAnimationThreeB + 2
							startAnimationThree = 2
						end
					end
					if (timeAnimationThreeA >= timeAnimationThreeB) then
						if (startAnimationThree == 2) then
							startAnimationThree = 0
							moles[3].y = -12/allScaleY
							moles[3].result = -999
						end
					end
				
					if (timeAnimationFourA < timeAnimationFourB) then
						if (startAnimationFour == 1) then
							moles[4].y = moles[4].y +.25/allScaleY
							timeAnimationFourA = gameTime
						end
						if (startAnimationFour == 2) then
							moles[4].y = moles[4].y -.25/allScaleY
							timeAnimationFourA = gameTime
						end
					end
					if (timeAnimationFourA >= timeAnimationFourB) then
						if (startAnimationFour == 1) then
							timeAnimationFourB = timeAnimationFourB + 2
							startAnimationFour = 2
						end
					end
					if (timeAnimationFourA >= timeAnimationFourB) then
						if (startAnimationFour == 2) then
							startAnimationFour = 0
							moles[4].y = 101/allScaleY
							moles[4].result = -999
						end
					end
					
					if (timeAnimationFiveA < timeAnimationFiveB) then
						if (startAnimationFive == 1) then
							moles[5].y = moles[5].y +.25/allScaleY
							timeAnimationFiveA = gameTime
						end
						if (startAnimationFive == 2) then
							moles[5].y = moles[5].y -.25/allScaleY
							timeAnimationFiveA = gameTime
						end
					end
					if (timeAnimationFiveA >= timeAnimationFiveB) then
						if (startAnimationFive == 1) then
							timeAnimationFiveB = timeAnimationFiveB + 2
							startAnimationFive = 2
						end
					end
					if (timeAnimationFiveA >= timeAnimationFiveB) then
						if (startAnimationFive == 2) then
							startAnimationFive = 0
							moles[5].y = 101/allScaleY
							moles[5].result = -999
						end
					end
					
					if (timeAnimationSixA < timeAnimationSixB) then
						if (startAnimationSix == 1) then
							moles[6].y = moles[6].y +.25/allScaleY
							timeAnimationSixA = gameTime
						end
						if (startAnimationSix == 2) then
							moles[6].y = moles[6].y -.25/allScaleY
							timeAnimationSixA = gameTime
						end
					end
					if (timeAnimationSixA >= timeAnimationSixB) then
						if (startAnimationSix == 1) then
							timeAnimationSixB = timeAnimationSixB + 2
							startAnimationSix = 2
						end
					end
					if (timeAnimationSixA >= timeAnimationSixB) then
						if (startAnimationSix == 2) then
							startAnimationSix = 0
							moles[6].y = 101/allScaleY
							moles[6].result = -999
						end
					end
					
					if (timeAnimationSevenA < timeAnimationSevenB) then
						if (startAnimationSeven == 1) then
							moles[7].y = moles[7].y +.25/allScaleY
							timeAnimationSevenA = gameTime
						end
						if (startAnimationSeven == 2) then
							moles[7].y = moles[7].y -.25/allScaleY
							timeAnimationSevenA = gameTime
						end
					end
					if (timeAnimationSevenA >= timeAnimationSevenB) then
						if (startAnimationSeven == 1) then
							timeAnimationSevenB = timeAnimationSevenB + 2
							startAnimationSeven = 2
						end
					end
					if (timeAnimationSevenA >= timeAnimationSevenB) then
						if (startAnimationSeven == 2) then
							startAnimationSeven = 0
							moles[7].y = 214/allScaleY
							moles[7].result = -999
						end
					end	
					
					if (timeAnimationEightA < timeAnimationEightB) then
						if (startAnimationEight == 1) then
							moles[8].y = moles[8].y +.25/allScaleY
							timeAnimationEightA = gameTime
						end
						if (startAnimationEight == 2) then
							moles[8].y = moles[8].y -.25/allScaleY
							timeAnimationEightA = gameTime
						end
					end
					if (timeAnimationEightA >= timeAnimationEightB) then
						if (startAnimationEight == 1) then
							timeAnimationEightB	= timeAnimationEightB + 2
							startAnimationEight = 2
						end
					end
					if (timeAnimationEightA >= timeAnimationEightB) then
						if (startAnimationEight == 2) then
							startAnimationEight = 0
							moles[8].y = 214/allScaleY
							moles[8].result = -999
						end
					end
					
					if (timeAnimationNineA < timeAnimationNineB) then
						if (startAnimationNine == 1) then
							moles[9].y = moles[9].y +.25/allScaleY
							timeAnimationNineA = gameTime
						end
						if (startAnimationNine == 2) then
							moles[9].y = moles[9].y -.25/allScaleY
							timeAnimationNineA = gameTime
						end
					end
					if (timeAnimationNineA >= timeAnimationNineB) then
						if (startAnimationNine == 1) then
							timeAnimationNineB = timeAnimationNineB + 2
							startAnimationNine = 2
						end
					end
					if (timeAnimationNineA >= timeAnimationNineB) then
						if (startAnimationNine == 2) then
							startAnimationNine = 0
							moles[9].y = 214/allScaleY
							moles[9].result = -999
						end
					end	
					
					if (startQuestion == 0) then
						numberResult = math.random(1, 20)
						labelQuestion.text = "that gives: "..numberResult
						startQuestion = 1
					end
					
					if (system:getTime() < 60) then
						timeLeft = 60 - math.floor(system:getTime())
						if (timeLeft == 5 and finalSeconds == 5) then
							audio:playStream("sound/second.mp3", false)
							finalSeconds = 4
							elseif (timeLeft == 4 and finalSeconds == 4) then
							audio:playStream("sound/second.mp3", false)
							finalSeconds = 3
							elseif (timeLeft == 3 and finalSeconds == 3) then
							audio:playStream("sound/second.mp3", false)
							finalSeconds = 2
							elseif (timeLeft == 2 and finalSeconds == 2) then
							audio:playStream("sound/second.mp3", false)
							finalSeconds = 1
							elseif (timeLeft == 1 and finalSeconds == 1) then
							audio:playStream("sound/second.mp3", false)
							finalSeconds = 5
						end
						else
						runGame = "end"
					end
				elseif (runGame == "end") then
		-----------win Game
					runGame = "restart"
					scoreWin.text = "¡TIME OUT!"
					scoreTitle.text = "Your Score is:"
					scoreText.text = scoreNumber
					buttonRestart.isVisible = true
					labelRestart.isVisible = true
					buttonRestart.y = 10/allScaleY
					labelRestart.y = buttonRestart.y-6/allScaleY
					labelQuestion.isVisible = false
					labelQuestionOne.isVisible = false
					scoreRectangle.isVisible = true
					scoreTitle.isVisible = true
					scoreWin.isVisible = true
					scoreText.isVisible = true
					timeLeft = 0
					labelTimeNumber.text = 0
					
					moles[1].y = -12/allScaleY
					moles[2].y = -12/allScaleY
					moles[3].y = -12/allScaleY
					moles[4].y = 101/allScaleY
					moles[5].y = 101/allScaleY
					moles[6].y = 101/allScaleY
					moles[7].y = 214/allScaleY
					moles[8].y = 214/allScaleY
					moles[9].y = 214/allScaleY
					
					for i = 1, 9 do
					moles[i].result = -999
					end
					
					if (selectGame == "beginner") then
						local file = io.open("scorebeginner.txt")
						scoreListBeginnerOne = tonumber(file:read())
						scoreListBeginnerTwo = tonumber(file:read())
						scoreListBeginnerThree = tonumber(file:read())
						file:close()
										
						if (scoreNumber > scoreListBeginnerOne) then
							scoreTitle.text = "GREAT SCORE:"
							scoreListBeginnerThree = scoreListBeginnerTwo
							scoreListBeginnerTwo = scoreListBeginnerOne
							scoreListBeginnerOne = scoreNumber
							elseif (scoreNumber > scoreListBeginnerTwo) then
								scoreTitle.text = "GREAT SCORE:"
								scoreListBeginnerThree = scoreListBeginnerTwo
								scoreListBeginnerTwo = scoreNumber
									elseif (scoreNumber > scoreListBeginnerThree) then
									scoreTitle.text = "GREAT SCORE:"
									scoreListBeginnerThree = scoreNumber
						end
						
						file = io.open("scorebeginner.txt", "w")
						file:write(scoreListBeginnerOne.."\n")
						file:write(scoreListBeginnerTwo.."\n")
						file:write(scoreListBeginnerThree.."\n")
						file:close()
					end
					 
					if (selectGame == "expert") then
						file = io.open("scoreexpert.txt")
						scoreListExpertOne = tonumber(file:read())
						scoreListExpertTwo = tonumber(file:read())
						scoreListExpertThree = tonumber(file:read())
						file:close()
						
						if (scoreNumber > scoreListExpertOne) then
							scoreTitle.text = "GREAT SCORE:"
							scoreListExpertThree = scoreListExpertTwo
							scoreListExpertTwo = scoreListExpertOne
							scoreListExpertOne = scoreNumber
							elseif (scoreNumber > scoreListExpertTwo) then
								scoreTitle.text = "GREAT SCORE:"
								scoreListExpertThree = scoreListExpertTwo
								scoreListExpertTwo = scoreNumber
									elseif (scoreNumber > scoreListExpertThree) then
									scoreTitle.text = "GREAT SCORE:"
									scoreListExpertThree = scoreNumber
						end
						
						file = io.open("scoreexpert.txt", "w")
						file:write(scoreListExpertOne.."\n")
						file:write(scoreListExpertTwo.."\n")
						file:write(scoreListExpertThree.."\n")
						file:close()
					end
					else
					-- stand by
				end
				labelScoreNumber.text = scoreNumber
				labelTimeNumber.text = timeLeft
			end
		end
		
		function buttonRestart:touch(event)
			if (event.phase == 'began') then
				moles[1].y = -12/allScaleY
				moles[2].y = -12/allScaleY
				moles[3].y = -12/allScaleY
				moles[4].y = 101/allScaleY
				moles[5].y = 101/allScaleY
				moles[6].y = 101/allScaleY
				moles[7].y = 214/allScaleY
				moles[8].y = 214/allScaleY
				moles[9].y = 214/allScaleY
				pause = false
				buttonRestart.isVisible = false
				buttonRestart.y = -100/allScaleY
				labelRestart.y = buttonRestart.y
				labelQuestion.isVisible = true
				labelQuestionOne.isVisible = true
				labelRestart.isVisible = false
				scoreRectangle.isVisible = false
				scoreTitle.isVisible = false
				scoreWin.isVisible = false
				scoreText.isVisible = false
				gameTime = 0;
				startAnimationOne = 0;
				startAnimationTwo = 0;
				startAnimationThree = 0;
				startAnimationFour = 0;
				startAnimationFive = 0;
				startAnimationSix = 0;
				startAnimationSeven = 0;
				startAnimationEight = 0;
				startAnimationNine = 0;
				moleAleatory = 0;
				operatorAleatory = 0;
				startQuestion = 0;
				numberOne = 0;
				numberTwo = 0;
				numberResult = 0;
				selectMole = 0;
				moleTrue = 0;
				labelOperator = "";
				moleWin = "";
				scoreNumber = 0;
				runGame = "run";
				finalSeconds = 5;
		
				system.debugTime = nil
				system.gameTime = 0
				system.timers = {}
				
			end
		end
		buttonRestart:addEventListener('touch', buttonRestart)
		
		function buttonQuit:touch(event)
			if (event.phase == 'began') then
				system:quit()
			end
		end
		buttonQuit:addEventListener('touch', buttonQuit)
			
		local onTouch = function(event)
			local mole = event.target
			if event.phase == "began" then
				if (mole.result == -999) then
					dbg.print("invalid")
				elseif (mole.result == numberResult) then
					audio:playStream("sound/win.mp3", false)
					scoreNumber = scoreNumber + 1
					startQuestion = 0
					else	
					audio:playStream("sound/lose.mp3", false)
					scoreNumber = scoreNumber - 2
				end
			elseif event.phase == "ended" then
			end
		end
		moles[1]:addEventListener("touch", onTouch)
		moles[2]:addEventListener("touch", onTouch)
		moles[3]:addEventListener("touch", onTouch)
		moles[4]:addEventListener("touch", onTouch)
		moles[5]:addEventListener("touch", onTouch)
		moles[6]:addEventListener("touch", onTouch)
		moles[7]:addEventListener("touch", onTouch)
		moles[8]:addEventListener("touch", onTouch)
		moles[9]:addEventListener("touch", onTouch)
		system:addEventListener("update", move)
	end
end

function scene:tearDown(event)
	self:releaseResources();
    dbg.print("sceneGame:tearDown")
end

scene:addEventListener({"setUp", "tearDown"}, scene)
return scene -- We must return the scene object!